
%% ex1

function cell = keygen(N,imin,imax,char,prob)

    cell = {};
    lenChar = length(char);
    
%validar args
    if nargin < 4
        error('wrong number of inputs')
    
    else if nargin == 4
        prob(1,1:lenChar) = 0.5;
   
    else 
        lenProb = length(prob);
        if lenProb ~= lenChar
            print("Array lengths don't match")
            exit
        end
    end
    
   
 %criar keys

    for k = 1 : N
        lenKey = randi([imin,imax]);
       % key = char(randi(numel(char),1,lenKey));
        key = randsample(char,lenKey,true,prob);
       % key = randsrc(lenKey,1,[char; prob]);
        cell{k} = key;
      
        noDupe = unique(cell);

    %caso seja duplicado
       if numel(cell) ~= numel(noDupe)
            key = randsample(char,lenKey,true,prob);
           cell{k} = key;
                     k = k-1;
       end

    end

end


%% ex2


